package com.sblab.mvc.rest;

import java.util.concurrent.atomic.AtomicLong;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sblab.mvc.domain.Greeting;

/**
 * Handles requests for the application home page.
 */
@RestController
public class RestMainController {
	
	private static final Logger logger = LoggerFactory.getLogger(RestMainController.class);
	private static final String template = "Hello, %s!";
    private final AtomicLong counter = new AtomicLong();

	
	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@RequestMapping("/greeting")
	public Greeting home(@RequestParam(value="name", defaultValue="World") String name) {

		return new Greeting(counter.incrementAndGet(), String.format(template, name));
	}
	
}
